#include <SDL3/SDL.h>

int main(int argc, char* argv[]) {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* window = SDL_CreateWindow(
        "Borderless Drag",
        640, 480,
        SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE
    );

    bool is_dragging = false;
    float drag_start_x, drag_start_y;
    int win_start_x, win_start_y;

    bool running = true;
    while (running) {
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
                case SDL_EVENT_MOUSE_BUTTON_DOWN:
                    if (event.button.button == SDL_BUTTON_LEFT) {
                        SDL_GetWindowPosition(window, &win_start_x, &win_start_y);
                        SDL_GetGlobalMouseState(&drag_start_x, &drag_start_y);
                        is_dragging = true;
                    }
                    break;

                case SDL_EVENT_MOUSE_MOTION:
                    if (is_dragging) {
                        float current_x, current_y;
                        SDL_GetGlobalMouseState(&current_x, &current_y);
                        SDL_SetWindowPosition(
                            window,
                            win_start_x + (current_x - drag_start_x),
                            win_start_y + (current_y - drag_start_y)
                        );
                    }
                    break;

                case SDL_EVENT_MOUSE_BUTTON_UP:
                    if (event.button.button == SDL_BUTTON_LEFT) {
                        is_dragging = false;
                    }
                    break;

                case SDL_EVENT_QUIT:
                    running = false;
                    break;
            }
        }
    }

    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}